package com.utils;

import com.opencsv.bean.CsvBindByName;
import com.opencsv.bean.CsvDate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author : wilbur.yuan
 * @date : 2019-04-16
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderProfit {

    @CsvBindByName(column = "USER_ID")
    private Long uid;

    @CsvBindByName(column = "MERCHANT_ORDER_NO")
    private String orderNo;

    @CsvBindByName(column = "ITEM_ID")
    private Long itemId;

    @CsvBindByName(column = "AMOUNT")
    private BigDecimal amount;

    @CsvBindByName(column = "DURATION_DAYS")
    private Integer durationDays;

    @CsvBindByName(column = "START_TIME")
    @CsvDate("yyyy-MM-dd'T'HH:mm:ss")
    private Date startDate;

    @CsvBindByName(column = "END_TIME")
    @CsvDate("yyyy-MM-dd'T'HH:mm:ss")
    private Date endTime;

    @CsvBindByName(column = "PURCHASE_TIME")
    @CsvDate("yyyy-MM-dd'T'HH:mm:ss")
    private Date purchaseTime;

    @CsvBindByName(column = "REFUND_TIME")
    @CsvDate("yyyy-MM-dd'T'HH:mm:ss")
    private Date refundTime;


    public static void main(String[] args) {
        List<OrderProfit> orderProfits = new ArrayList<>(2);
        orderProfits.add(OrderProfit.builder().purchaseTime(new Date(123456789L)).build());
        orderProfits.add(OrderProfit.builder().purchaseTime(new Date(1234567890L)).build());
        orderProfits.sort((OrderProfit o1, OrderProfit o2)->
                 o1.getPurchaseTime().before(o2.getPurchaseTime()) ? -1 : 1
        );
        System.out.println(orderProfits);
    }
}
